<?php
namespace app\index\controller;
use think\Db;
use think\Controller;
use think\Cookie;
class Index extends Base{

    public function index(){

       /* $data = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'1'])
            ->field('title,id,createtime')
            ->order('createtime','desc')
            ->paginate(8);*/

       

       /* $qjxy = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'9'])
            ->field('title,id,createtime')
            ->order('id','desc')
            ->paginate(9);

        $tzrd = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'3'])
            ->field('title,id,createtime')
            ->order('createtime','desc')
            ->paginate(8);

        $clzx = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'4'])
            ->field('title,id,createtime')
            ->order('id','desc')
            ->paginate(5);

        $jcp = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'5'])
            ->field('title,id,createtime')
            ->order('id','desc')
            ->paginate(5);
        $tzll = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'6'])
            ->field('title,id,createtime')
            ->order('id','desc')
            ->paginate(5);
        $hydt = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'8'])
            ->field('title,id,createtime')
            ->order('createtime','desc')
            ->paginate(9);
        $tzrd = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'3'])
            ->field('title,id,createtime')
            ->order('id','desc')
            ->paginate(8);
        $mtbd = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'7'])
            ->field('title,id,createtime')
            ->order('createtime','desc')
            ->paginate(9);
        $qjdt = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'10'])
            ->order('id','desc')
            ->find();

        $mtbds = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'7'])
            ->where('photo','not in','')
            ->field('id,synopsis,title,photo,classification')
            ->order('id','desc')
            ->find();*/
        // dump($mtbds);die;
/*        $hydts = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'8'])
            ->where('photo','not in','')
            ->field('id,synopsis,title,photo,content')
            ->order('id','desc')
            ->find();
       
        $jcps = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'5'])
            ->field('id,synopsis,title,photo,content,classification')
            ->order('id','desc')
            ->find();
        $tzlls = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'6'])
            ->field('id,synopsis,title,photo,content,classification')
            ->order('id','desc')
            ->find();
        $dttp = Db::name('cms_article')
            ->where(['classification'=>10,'status'=>1])
            ->order('id','desc')
            ->field('photo,title,id,synopsis')
            ->paginate(5);

        $spzs = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'20'])
            ->field('title,id,photo')
            ->order('id','desc')
            ->select();
         $yqlj = Db::name('cms_cooperation')->where('type',1)->where('status','not in',2)->select();*/
        $hzhb = Db::name('cms_cooperation')->where('type',2)->where('status=1')->select();
      
          $jrzx = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'1'])
            ->field('title,id,createtime')
            ->order('createtime','desc')
            ->paginate(3);
            
        $gsxw = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'3'])
            ->field('id,synopsis,title,photo,content,classification,createtime')
            ->order('id','desc')
            ->select();
        
        $gsgg = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'1'])
            ->field('id,synopsis,title,photo,content,classification,createtime')
            ->order('id','desc')
            ->select();
        
        $xwtp = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'3'])
            ->where('photo','neq','')
            ->field('id,synopsis,title,photo,content,classification,createtime')
            ->order('id','desc')
            ->select();
     
       
        $clzxs = Db::name('cms_article')
            ->where(['status'=>1,'classification'=>'2'])
            ->field('id,synopsis,title,photo,content,classification,createtime')
            ->order('id','desc')
            ->select();
        $photo = Db::name('cms_broadcast')->where(['status'=>1])->select();

        return view('Index/index',['clzxs'=>$clzxs,'photo'=>$photo,'jrzx'=>$jrzx,'hzhb'=>$hzhb,'gsxw'=>$gsxw,'gsgg'=>$gsgg,'xwtp'=>$xwtp]);
    }

//    public function content(){
//        return view('Index/content');
//    }
    public function presentation(){
        if(empty($_GET['classify'])){
            $data = Db::name('cms_article')
                ->where(['status'=>1])
                ->order('id','desc')
                ->paginate(20,false,['query'=>$_GET]);
            $typename = '文章列表';
            $gid = 0;
        }else{
            $data = Db::name('cms_article')
                ->where(['classification'=>$_GET['classify'],'status'=>1])
                ->order('id','desc')
                ->paginate(20,false,['query'=>$_GET]);
            $typename = Db::name('cms_type')->where('id',$_GET['classify'])->field('typename')->find()['typename'];
            $gid = $_GET['classify'];
        }
        $type = Db::name('cms_type')->where('status',1)->field('id,typename')->select();
        $page = $data->render();
        return view('Index/list',['typename'=>$typename,'data'=>$data,'type'=>$type,'gid'=>$gid,'page'=>$page]);
    }
    public function searchList(){
        $data = Db::name('cms_article')
            ->where('title','like',"%{$_GET['name']}%")
            ->where('status',1)
            ->order('id','desc')
            ->paginate(20,false,['query'=>$_GET]);
//        dump($data);die;
        $typename = $_GET['name'];
        $gid = 0;
        $type = Db::name('cms_type')->where('status',1)->field('id,typename')->select();
        $page = $data->render();
        return view('Index/list',['typename'=>$typename,'data'=>$data,'type'=>$type,'gid'=>$gid,'page'=>$page]);
    }
    public function content(){
        $content = Db::name('cms_article')->where(['id'=>$_GET['id'],'status'=>1])->find();
        $typename=Db::name('cms_type')->where('id',$content['classification'])->find()['typename'];
        $type = Db::name('cms_type')->where('status',1)->field('id,typename')->select();
        $hzhb = Db::name('cms_cooperation')->where('type',2)->where('status','not in',2)->select();
        $yqlj = Db::name('cms_cooperation')->where('type',1)->where('status','not in',2)->select();
        $typename = Db::name('cms_type')->where(['id'=>$content['classification']])->find()['typename'];
        return view('Index/content',['typename'=>$typename,'yqlj'=>$yqlj,'hzhb'=>$hzhb,'type'=>$type,'gid'=>$content['classification'],'content'=>$content,'typename'=>$typename]);
    }

    public function download(){
        return view('Download/index');
    }
    public function description(){
        return view('Download/description');
    }


//    public function addconter(){
//        // $url  = 'http://www.lcqjgj.com/index.php?ctl=article&id=461';
//        $url  = $_POST['url'];
//        // echo $url;die;
//        $text=file_get_contents($url);
//        // dump($text);
//        //取出 div 标签且 id 为 PostContent 的內容，并储存至二维数组 $match 中
//        preg_match('/<div[^>]*class="article_info"[^>]*>.*?<\/div>/si',$text,$match);
//        preg_match('|<title>(.*?)<\/title>|i',$text,$m);
//
//        $this->assign('conter',$match[0]);
//        $this->assign('title',substr($m[1],0,-15));
//        return $this->fetch('Index/addconter');
//    }
//
//    public function add(){
//        $data = [
//            'title' => $_POST['title'],
//            'classification' => $_POST['classification'],
//            'content' => $_POST['editorValue'],
//            'publisher' => Session::get('uid'),
//        ];
//        $a = Db::name('cms_article')->insert($data);
//        if($a) return "<script>alert('添加成功');history.go(-1);</script>";
//    }


//    public function index_xhgp(){
//        return $this->fetch('Index/index_xhgp');
//    }
    public function index_xhgp(){
        return view('Index/index_xhgp');
    }
    public function aindex(){
        return view('Index/aindex');
    }

}
